#include <tsin/runtime/FrontBlitWork.hpp>

#include <tsin/runtime/GameRuntime.hpp>

#include <tsin/display/Display.hpp>
#include <tsin/display/Image.hpp>
#include <tsin/display/DecoratedImage.hpp>
#include <tsin/library/Game.hpp>
#include <tsin/library/Front.hpp>

#include <tsin/util/MemCheck.hpp>
using namespace tsin;

FrontBlitWork::FrontBlitWork()
        : image(0)
{
}

FrontBlitWork::~FrontBlitWork()
{
        if (image != 0)
                delete image;
}

void FrontBlitWork::init(GameRuntime *runtime)
{
        this->front = runtime->game->getFront();
        this->display = &runtime->display;

        Image *image = display->openImage(runtime->game->getFrontImagePath(), runtime->game->getResolution());
        this->image = new DecoratedImage(*image);
        image->unref();
}

int FrontBlitWork::run()
{
        display->useOverallFrame();
        front->paint(*display, *image);
        return 0;
}